package com.tj.jinzao.presenter;


import android.util.Log;

import com.tj.jinzao.api.SubscriberCallBack;
import com.tj.jinzao.base.BasePresenter;
import com.tj.jinzao.callback.ICaseView;
import com.tj.jinzao.manager.UserManager;
import com.tj.jinzao.model.ResultResponse;
import com.tj.jinzao.model.Target;
import com.tj.jinzao.model.User;

import java.util.List;
import java.util.Map;

/**
 * 身体状态和目标
 * Created by wjy 2018/12/10.
 */
public class CompleteInfoPresenter extends BasePresenter<ICaseView<List<Target>>> {

    public CompleteInfoPresenter(ICaseView<List<Target>> view) {
        super(view);
    }

    //获取个人目标
    public void getPersonTarget() {
        addSubscription(mApiService.getTargetList(), new SubscriberCallBack<List<Target>>(mView.getContext()) {
            @Override
            protected void onSuccess(List<Target> targets) {
                if (mView != null) mView.onRequestSuccess(targets);
            }

            @Override
            protected void onFailure(ResultResponse response) {
                if (mView != null) mView.onRequestError(response.getMessage());
            }
        });
    }

    //获取咨询师用户标签
    public void getPersonTargetZxs() {
        addSubscription(mApiService.getTargetUserList(), new SubscriberCallBack<List<Target>>(mView.getContext()) {
            @Override
            protected void onSuccess(List<Target> targets) {
                if (mView != null) mView.onRequestSuccess(targets);
            }

            @Override
            protected void onFailure(ResultResponse response) {
                if (mView != null) mView.onRequestError(response.getMessage());
            }
        });
    }
    //获取身体状况
    public void getPhysicalCondition() {
        addSubscription(mApiService.getPhysicalList(), new SubscriberCallBack<List<Target>>(mView.getContext()) {
            @Override
            protected void onSuccess(List<Target> targets) {
                if (mView != null) mView.onRequestSuccess(targets);
            }

            @Override
            protected void onFailure(ResultResponse response) {
                if (mView != null) mView.onRequestError(response.getMessage());
            }
        });
    }

    public void updateInfo(Map<String, Object> map) {
        long id = UserManager.getInstance().getUser().getId();
        addSubscription(mApiService.updateUserInfo(id,map), new SubscriberCallBack<User>(mView.getContext()) {
            @Override
            protected void onSuccess(User user) {
                Log.w("用户信息接口","wwwwaa"+user.toString());
                UserManager.saveUserData(user);
                if (mView != null) mView.onRequestSuccess(null);
            }

            @Override
            protected void onFailure(ResultResponse response) {
                Log.w("用户信息接口","wwww"+response.toString());
                if (mView != null) mView.onRequestError(response.getMessage());
            }
        });
    }
}